package com.java.zhuiyun.api.live.mapper;

import com.java.zhuiyun.api.live.entity.Live;
import com.java.zhuiyun.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface LiveMapper extends BaseMapper<Live> {
    /**
    * @Author MJL
    * @Description 查询所有直播间信息
    * @Date 2023/8/21 14:07
    * @Return  * @param null
    */
    @Select("SELECT l.*,t.nick_name, \n" +
            "d.dict_name from live l \n" +
            "INNER JOIN sys_user t ON l.teacher_id = t.id \n" +
            "INNER JOIN sys_dict d ON l.dict_id = d.id \n" +
            "WHERE l.del_flag = 0 AND l.live_status = 0 ")
    List<Live> queryLive(Live live);

    /**
    * @Author MJL
    * @Description todo 将违规直播间封禁
    * @Date 2023/8/21 14:07
    * @Return  * @param null
    */
    @Update("update live set live_room_status = 1 where id = #{id}")
        int banned(Integer id);

    /**
    * @Author MJL
    * @Description todo 将直播间解封
    * @Date 2023/8/21 14:13
    * @Return  * @param null
    */
    @Update("update live set live_room_status = 0 where id = #{id}")
    int enable(Integer id);

    /**
    * @Author MJL
    * @Description todo 检查房间号是否重复
    * @Date 2023/8/23 14:00
    * @Return  * @param null
    */
    @Select("select count(0) from live where room_num = #{roomNum}")
    Integer checkRoomNum(int roomNum);

    /**
    * @Author MJL
    * @Description todo 根据教师id查看直播信息
    * @Date 2023/8/23 14:44
    * @Return  * @param null
    */
    @Select("select * from live where teacher_id = #{teacherId} and live_status = 0")
    Live getLiveByUserId(Integer teacherId);

    /**
    * @Author MJL
    * @Description todo 检验当前主播是否正在直播
    * @Date 2023/8/23 15:31
    * @Return  * @param null
    */
    @Select("select count(0) from live where teacher_id = #{teacherId} and live_status = 0")
    Integer checkLiveByUserId(Integer teacherId);

    /**
    * @Author MJL
    * @Description todo 关闭直播
    * @Date 2023/8/24 15:57
    * @Return  * @param null
    */
    @Update("update live set live_status = 1 , del_flag = 1 , update_time = #{updateTime} where id = #{id}")
    int closeLive(Live live);

    /**
    * @Author MJL
    * @Description todo 根据id查询直播间信息
    * @Date 2023/8/24 16:29
    * @Return  * @param null
    */
    @Select("select * from live where id = #{id}")
    Live getLiveById(Integer id);
}
